package com.example.ecommercedemo.service.impl;

import java.util.List;

import com.example.ecommercedemo.entity.Good;
import com.example.ecommercedemo.mapper.GoodMapper;
import com.example.ecommercedemo.service.GoodService;
import com.example.ecommercedemo.utils.PageResult;
import com.example.ecommercedemo.utils.PageUtils;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Service
public class GoodServiceImpl implements GoodService
{
    @Autowired
    private GoodMapper goodMapper;

//    查询good
    @Override
    public Good selectGoodByGid(Long gid)
    {
        return goodMapper.selectGoodByGid(gid);
    }

//    查询good列表
    @Override
    public PageResult selectGoodList(Good good, int pageNum, int pageSize)
    {
        //调用pageHelper插件
        PageHelper.startPage(pageNum,pageSize);
        List<Good> list=goodMapper.selectGoodList(good);//分页数据
        System.out.println(list.size());
        PageInfo<Good> pageInfo=new PageInfo<>(list);
        PageResult pageResult= PageUtils.getPageResult(pageInfo);
        return  pageResult;
    }

//    新增good
    @Override
    public int insertGood(Good good)
    {
        return goodMapper.insertGood(good);
    }

//    修改good
    @Override
    public int updateGood(Good good)
    {
        return goodMapper.updateGood(good);
    }

//    批量删除good
    @Override
    public int deleteGoodByGids(Long[] gids)
    {
        return goodMapper.deleteGoodByGids(gids);
    }

//    删除good信息
    @Override
    public int deleteGoodByGid(Long gid)
    {
        return goodMapper.deleteGoodByGid(gid);
    }


    @Override
    public Good selectGoodByCid(Long cid) {
        return goodMapper.selectGoodByCid(cid);
    }

    @Override
    public List<Good> selectGoodListBynot(Good good) {
        List<Good> list=goodMapper.selectGoodListBynot(good);
        return list;
    }
}
